﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightTcpClient
{
    public class Player
    {
        private CompositeTransform _rectTransform;
        private CompositeTransform _textTransform;

        public Rectangle DrawRect { get; private set; }
        public TextBlock TextBlock { get; private set; }
        public string Name { get; private set; }
        public Point Location { get; private set; }
        public byte Id { get; private set; }

        public Player(byte id, Canvas canvas, Color color, string name)
        {
            Id = id;

            _rectTransform = new CompositeTransform();

            DrawRect = new Rectangle();
            DrawRect.Width = 40;
            DrawRect.Height = 40;
            DrawRect.Fill = new SolidColorBrush(color);
            DrawRect.RenderTransform = _rectTransform;
            canvas.Children.Add(DrawRect);

            _textTransform = new CompositeTransform();

            TextBlock = new TextBlock();
            TextBlock.Text = "Nobody";
            TextBlock.RenderTransform = _textTransform;
            TextBlock.Text = name;
            Name = name;
            canvas.Children.Add(TextBlock);
        }

        public void UpdateForeign()
        {
            _rectTransform.TranslateX = Location.X;
            _rectTransform.TranslateY = Location.Y;

            _textTransform.TranslateX = Location.X;
            _textTransform.TranslateY = Location.Y - 20;

            TextBlock.Text = Name;
        }

        public void UpdateLocal(Point p)
        {
            _rectTransform.TranslateX = p.X;
            _rectTransform.TranslateY = p.Y;
            Location = p;

            _textTransform.TranslateX = Location.X;
            _textTransform.TranslateY = Location.Y - 20;
        }

        public void MoveAsync(Point p)
        {
            Location = p;
        }

        public void ChangeNameAsync(string name)
        {
            Name = name;
        }
    }
}
